package site.teamo.biu.net.common.message;

import site.teamo.biu.net.common.message.connect_to_destination_address.ConnectToDestinationAddressRequest;
import site.teamo.biu.net.common.message.connect_to_destination_address.ConnectToDestinationAddressResponse;

import java.util.HashMap;
import java.util.Map;

/**
 * @author haocongshun
 * @date 2023/02/10 10:38:57
 */
public interface Message {

    //BIU-NET
    long flag = 66_73_85_45_78_69_84L;

    Type type();

    enum Type {
        //http&https代理客户端向代理服务端请求连接目标地址消息
        CONNECT_TO_DESTINATION_ADDRESS_REQUEST(101, ConnectToDestinationAddressRequest.class),
        //http&https代理服务端对代理客户端的连接目标地址的响应
        CONNECT_TO_DESTINATION_ADDRESS_RESPONSE(102, ConnectToDestinationAddressResponse.class);


        public final int code;

        public final Class<? extends Message> tClass;

        Type(int code, Class<? extends Message> tClass) {
            this.code = code;
            this.tClass = tClass;
        }

        private static final Map<Integer, Type> map = new HashMap<>();

        static {
            for (Type value : values()) {
                map.put(value.code, value);
            }
        }

        public static Type codeOf(int code) {
            return map.get(code);
        }

    }
}
